from django.db import models

class City(models.Model):
    name = models.CharField(max_length=50, unique=True)
    description = models.TextField(blank=True)

class DataCenter(models.Model):
    name = models.CharField(max_length=50)
    city = models.ForeignKey(City, on_delete=models.CASCADE)
    address = models.CharField(max_length=200)

class Host(models.Model):
    ip = models.GenericIPAddressField(unique=True)
    name = models.CharField(max_length=100)
    data_center = models.ForeignKey(DataCenter, on_delete=models.CASCADE)
    is_active = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)

class HostStat(models.Model):
    city = models.ForeignKey(City, on_delete=models.CASCADE)
    data_center = models.ForeignKey(DataCenter, on_delete=models.CASCADE)
    host_count = models.PositiveIntegerField()
    stat_date = models.DateField()
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        unique_together = ('city', 'data_center', 'stat_date')